﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using Module.DataAccess;
using Module.EntitiesInfo;


namespace Module.BusinessLogic
{
    public class CategoryBL
    {
        public static DataTable GetAll()
        {
            try
            {
                return new CategoryDB().GetAll();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static void Delete(int id)
        {
            try
            {
                new CategoryDB().Delete(id);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static int Insert(string title, double rate)
        {
            try
            {
                return new CategoryDB().Insert(title, rate);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static void Update(int id, string title, double rate)
        {
            try
            {
                new CategoryDB().Update(id, title, rate);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static CategoryInfo GetInfo(int id)
        {
            try
            {
                CategoryInfo categoryInfo=new CategoryInfo();
                categoryInfo=ObjectHelper.FillObject<CategoryInfo>(new CategoryDB().GetInfo(id));
                if(categoryInfo !=null)
                    return categoryInfo;
                return null;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static void FillDropList(ListControl ctrlList, string selectedValue)
        {
            try
            {
                DataTable dt = new DataTable();
                dt = GetAll();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        ListItem _item = new ListItem(dr["Title"].ToString(), dr["Id"].ToString());
                        if (_item.Value == selectedValue) _item.Selected = true;
                        ctrlList.Items.Add(_item);
                    }
                }

            }
            catch (Exception ex)
            {
                throw;
            }
        }

        static string Getvalue(int Rate)
        {
            string str = "";
            if (Rate == 1)
                str = "Bình thường";
            else if (Rate == 2)
                str = "Khó";
            else if (Rate == 3)
                str = "Dễ";
            else
                str = "N/A";
            return str;
        }


    }
}

